package com.fmi.cloud.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

/**
 * 获取系统信息
 * Created by zv on 2015/11/20.
 */
public class SystemInfoUtil {

    /**
     * 获取当前版本信息
     */
    public static String getVersionName(Context context) {
        String version = "unknown";
        try {
            PackageManager packageManager = context.getPackageManager();
            if (packageManager != null) {
                PackageInfo packInfo = packageManager.getPackageInfo(
                        context.getPackageName(), 0);
                if (packInfo != null) {
                    version = packInfo.versionName;
                }
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return version;
    }

    public static String getDeviceID(Context context) {
        String deviceID;
        TelephonyManager tm = (TelephonyManager) context.getSystemService(android.content.Context.TELEPHONY_SERVICE);
        deviceID = tm.getDeviceSoftwareVersion();
        if (TextUtils.isEmpty(deviceID)) {
            deviceID = "";
        }
        return deviceID;
    }
}
